[Docker][Ubuntu 18.04]中文环境配置
当前主要使用Docker Ubuntu 18.04
镜像,需要对官方镜像进行进一步配置以适应中文开发环境
阿里源替换
zh_CN.UTF_8字符集设置
时区设置
参考:
Synchronize timezone from host to container
apt-get install tzdata noninteractive
Docker Ubuntu 18.04
默认的时区和亚洲-上海时区相差8
个小时(东八区)
在Dockerfile
中增加以下命令
ENV DEBIAN_FRONTEND=noninteractive
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN apt-get install -y tzdata && dpkg-reconfigure --frontend noninteractive tzdata
还有一种方式是在使用docker run
命令时同步主机时区
$ docker run -v /etc/localtime:/etc/localtime:ro ...
编辑
Dockerfile
脚本如下:
FROM ubuntu:18.04
LABEL maintainer "zhujian <zjzstu@github.com>"
COPY sources.list .
ENV DEBIAN_FRONTEND=noninteractive
RUN mv sources.list /etc/apt/sources.list && \
apt-get update && \
apt-get install -y locales tzdata && \
locale-gen zh_CN.UTF-8 && \
update-locale LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 && \
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
dpkg-reconfigure --frontend noninteractive tzdata && \
find /var/lib/apt/lists -type f -delete && \
find /var/cache -type f -delete
ENV LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8
- 加载
docker
官方镜像ubuntu:18.04
- 复制源配置文件
sources.list
到镜像 - 替换源配置文件并更新安装列表,设置
zh_CN.UTF-8
并删除额外文件 - 设置字符集环境变量
构建
$ docker build -t zjzstu/ubuntu:18.04 -t zjzstu/ubuntu:latest .
使用
$ docker run -it --rm zjzstu/ubuntu bash
能够实现中文输入,确保中文文件不乱码